package tt.dz.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import tt.dz.dao.pro.UserPayCardDao;
import tt.dz.dao.pro.UserWalletDao;
import tt.dz.entity.UserPayCard;
import tt.dz.entity.UserWallet;
import tt.dz.service.UserWalletService;

/**
 * 用户电子钱包
 * @author Administrator
 *
 */
@Service
public class UserWalletServiceImpl implements UserWalletService{

	/**用户电子钱包Dao类*/
	@Resource
	UserWalletDao<UserWallet> userWalletDao;
	
	/**用户支付卡信息*/
	@Resource
	UserPayCardDao<UserPayCard> userPayCardDao;
	
	
	@Override
	public Double getUserWalletBalanceByCardNum(String cardNum) {
		
		UserPayCard userPayCard = userPayCardDao.findUserPayCardByCardNum(cardNum);
		if(userPayCard!=null){
			UserWallet userWallet = userWalletDao.findUserWalletByUserId(userPayCard.getUser_id());
			if(userWallet!=null){
				return userWallet.getBalance();
			}
		}
		return -99.0;
	}

	@Override
	public Double getUserWalletFreezeSum(String cardNum) {

		UserPayCard userPayCard = userPayCardDao.findUserPayCardByCardNum(cardNum);
		if(userPayCard!=null){
			UserWallet userWallet = userWalletDao.findUserWalletByUserId(userPayCard.getUser_id());
			if(userWallet!=null){
				return userWallet.getFreeze_sum();
			}
		}
		return -99.0;
	}

	@Override
	public UserWallet getUserWalletByUserId(int userId) {
		return userWalletDao.findUserWalletByUserId(userId);
	}

	@Override
	public void updateUserWallet(UserWallet userWallet) {
		userWalletDao.update(userWallet);
	}
}
